<?php
namespace app\admin\controller;

use think\App;
use hg\apidoc\annotation as Apidoc;
use app\common\lib\Show;
use app\common\model\JfArticle as JfArticleModel;
use think\Exception;

/**
 * @Apidoc\Title("掘粪文章管理")
 * @Apidoc\Group("JfArticle")
 * @Apidoc\Sort("9")
 */

class JfArticle extends AdminBaseController
{
  protected $jf_article_model;
  public function __construct(App $app)
  {
      parent::__construct($app);
      $this->jf_article_model = new JfArticleModel();
  }
  /**
   * @Apidoc\Title("掘粪文章列表")
   * @Apidoc\Desc("获取掘粪文章列表接口")
   * @Apidoc\Author("ckmmd")
   * @Apidoc\Url("/admin/jf/article/get_jf_articles")
   * @Apidoc\Method("POST")
   * @Apidoc\Tag("列表")
   * @Apidoc\Header( ref="auth")
   * @Apidoc\Header("auth", type="String",require=true, default="JfArticle", desc="权限验证" )
   * @Apidoc\Param( ref="pagingParam")
   * @Apidoc\Param("title", type="string",require=false, desc="文章标题查询" )
   * @Apidoc\Returned("data", type="object", desc="业务数据",
   *    @Apidoc\Returned( ref="pagingParam"),
   *    @Apidoc\Returned("list", type="array",ref="app\common\model\JfArticle\getJfArticleList", desc="数据列表")
   * )
   */
  public function getJfArticles(){
    if (!$this->request->isPost()) {
      return Show::error('错误的请求');
    }
    try {
      $qurey_info = $this->request->param();
      $articles = $this->jf_article_model->getJfArticleList($qurey_info, $this->super_user_auth);
      foreach ($articles['list'] as $article) {
        $article['user'] = $this->jf_article_model->user()->where('status', 1)->find($article['user_id']);
      }
      return Show::success($articles);
    } catch (Exception $e) {
      return Show::error($e->getMessage());
    }
  }
  /**
   * @Apidoc\Title("修改绝粪文章审核状态")
   * @Apidoc\Desc("修改绝粪文章审核状态接口")
   * @Apidoc\Author("ckmmd")
   * @Apidoc\Url("/admin/jf/article/audit_status_jf_article")
   * @Apidoc\Method("POST")
   * @Apidoc\Tag("修改数据状态")
   * @Apidoc\Header( ref="auth")
   * @Apidoc\Header("auth", type="String",require=true, default="auditStatusJfArticle", desc="权限验证" )
   * @Apidoc\Param("id", type="int",require=true, desc="文章ID" )
   * @Apidoc\Param("status", type="int",require=true, desc="状态：1（通过），0（下架）" )
   * @Apidoc\Returned("data", type="int", desc="业务数据")
   */
  public function auditStatusJfArticle()
  {
    if (!$this->request->isPost()) {
      return Show::error('错误的请求');
    }
    $qurey_info = $this->request->param();
    try {
      $result = $this->jf_article_model->auditStatusJfArticle($qurey_info);
      return Show::success($result);
    } catch (Exception $e) {
      return Show::error($e->getMessage());
    }
  }
}